package c.x.jy.wexin.controller;

import c.x.jy.common.annotation.Login;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.dao.entity.MemberEntity;
import c.x.jy.dao.entity.MemberWalletEntity;
import c.x.jy.service.service.MemberService;
import c.x.jy.service.service.MemberWalletService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 会员钱包表
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-25 10:48:03
 */
@RestController
@RequestMapping("wechat/memberwallet")
public class MemberWalletController {
    @Autowired
    private MemberWalletService memberWalletService;
    @Autowired
    private MemberService memberService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("member:memberwallet:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberWalletService.queryPage(params);

        return R.put(page);
    }

    @Login
    @RequestMapping("/getbymemberid")
    public R getByMemberId(){
        MemberEntity memberEntity = memberService.getCurrUser();

        MemberWalletEntity memberWallet = memberWalletService.getByMemberId(memberEntity.getId());
        return R.put(memberWallet);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("member:memberwallet:info")
    public R info(@PathVariable("id") Long id){
		MemberWalletEntity memberWallet = memberWalletService.getById(id);

        return R.put(memberWallet);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("member:memberwallet:save")
    public R save(@RequestBody MemberWalletEntity memberWallet){
		memberWalletService.save(memberWallet);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("member:memberwallet:update")
    public R update(@RequestBody MemberWalletEntity memberWallet){
		memberWalletService.updateById(memberWallet);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("member:memberwallet:delete")
    public R delete(@PathVariable("id") Long id){
		memberWalletService.removeByIds(Arrays.asList(id));

        return R.ok();
    }

}

